

#ifndef UDB_DBAUDITA_H
#define UDB_DBAUDITA_H 1

#include "zAdAChar.h"

#pragma pack(push, 8)

class UcDbDatabase;
class UcDbAuditInfo;
class UcDbImpAuditInfo;
class UcDbAuditImp;
class UcDbObject;

#define UCDB_AUDIT_RETURN(pAuditInfo, baseEs, localEs, boilDownLocalStatus)        \
    return (baseEs != eOk)                ?  \
               baseEs                     :  \
               (eOk == localEs)           ?  \
                   eOk                    :  \
                   boilDownLocalStatus    ?  \
                       (pAuditInfo->fixErrors()?  \
                           eFixedAllErrors     :  \
                           eLeftErrorsUnfixed) :  \
                       localEs;

class UcDbAuditInfo
{
public:

    friend class UcDbImpAuditInfo;
    friend class UcDbAuditImp;

    enum AuditPass {
            PASS1 = 1,
            PASS2 = 2
    };

    UcDbAuditInfo();
    ~UcDbAuditInfo();

    bool           fixErrors(void) const;

    int numErrors() const;

    int numFixes(void) const;

    void errorsFound(int count);

    void errorsFixed(int count);

    AuditPass auditPass(void) const;

    void printError(const ZTCHAR * name,
                    const ZTCHAR * value,
                    const ZTCHAR * validation,
                    const ZTCHAR * defaultValue);

    void printError(const UcDbObject *pObj,
                    const ZTCHAR * value,
                    const ZTCHAR * validation,
                    const ZTCHAR * defaultValue);

    void requestRegen();

    void resetNumEntities();
    
    void incNumEntities();

    int numEntities();

    void printNumEntities(const ZTCHAR* msg);
    Ucad::ErrorStatus fetchObject(UcDbObjectId    originalObjId,
                                    UcDbObjectId& newObjId,
                                    UcRxClass*    pObjClass,
                                    bool          uneraseIfPossible = false,
                                    bool          createIfNotFound = true,
                                    bool          externalDbOk = false);
    Ucad::ErrorStatus registerObject(UcDbHandle handle,
                                     bool       objIsValid,
                                     UcRxClass* pObjClass);
    Ucad::ErrorStatus updateObject( UcDbHandle   handle,
                                    bool         setFileObjIsValid,
                                    bool         setNewObjIsValid,
                                    bool         setFileObjClass,
                                    bool         setNewObjClass,
                                    bool         setNewObjId,
                                    bool         fileObjIsValid,
                                    bool         newObjIsValid,
                                    UcRxClass*   pFileObjClass,
                                    UcRxClass*   pNewObjClass,
                                    UcDbObjectId newObjId);

private:

    UcDbImpAuditInfo * getImpAudit() const;

    UcDbImpAuditInfo * mpImpAudit;
};

class UcDbRecover{

    public:
    virtual  int callBack(UcDbDatabase*) = 0;
};

class  UcDbImpRecoverCallBack;

class UcDbRecoverCallBack {

    public:
    UcDbRecoverCallBack();
    virtual ~UcDbRecoverCallBack();

    virtual  Ucad::ErrorStatus registerCallBack(UcDbRecover*);
    virtual  Ucad::ErrorStatus removeCallBack();

    private:

        UcDbImpRecoverCallBack *mpImpRecoverCallBack;

};

#pragma pack(pop)

#endif
